/**
 * 给定数组A和B，要求重排B，使得|Ai - Bi| <= K
 * 保证有答案
 * 排序以后，直接对应即可
 */
#include <bits/stdc++.h>
using namespace std;

#include <bits/extc++.h>
using namespace __gnu_pbds;

using llt = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

int N, K;
vi A, B;

void proc(){
    vector<pii> vec;
    vec.reserve(N);
    int k = 0;
    for(auto i : A) vec.emplace_back(i, k++);
    sort(vec.begin(), vec.end());

    sort(B.begin(), B.end());
    vi ans(N);
    for(int i=0;i<N;++i){
        ans[vec[i].second] = B[i];
    }
    for(auto i : ans) cout << i << " ";
    cout << endl;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(0);
    int nofkase = 1;
    cin >> nofkase;
    while(nofkase--){
        cin >> N >> K;
        A.assign(N, 0);
        for(auto & i : A) cin >> i;
        B.assign(N, 0);
        for(auto & i : B) cin >> i;
        proc();
    }
    return 0;
}